﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
-- =============================================
-- Author:		Adrian Kaczmarek
-- Mod date: 2013-08-19
-- Description:	Pobiera listę kolumn grupy
-- =============================================
ALTER PROCEDURE [dbo].[bhp_NemoGroupColumnsGet] (
	@GroupId				INT
)
WITH ENCRYPTION
AS
BEGIN
	SELECT 
		t.id as ColumnId,
		t.name as ColumnName,
		ct.EnumType as ColumnType,
		ISNULL(t.rel, 0) as RelatedGroupId,
		ISNULL(c.DisplayName, t.name) as DisplayName,
		ISNULL(c.FormattingValue, '{0}') as FormattingValue,
		ISNULL(c.Sort, 0) as ColumnSort,
		c.RegexValidation,
		c.[Description],
		ISNULL(c.HideForEdition, 0) as HideForEdition,
		ISNULL(dt.EditControl, c.CustomEditControl) as CustomEditControl,
		t.parent as BelongsToGroupId,
		CASE tp.typ WHEN 'V' THEN 0 ELSE 1 END as Editable,
		dt.Controller as DataTypeController
	FROM
		n_Tree t
		LEFT JOIN bht_Columns c ON t.id = c.ColumnId
		INNER JOIN bht_ColumnTypes ct ON CASE WHEN c.NemoDataType IS NULL THEN t.typ ELSE 'C' END = ct.ColumnType
		INNER JOIN n_Tree tp ON t.parent = tp.id
		LEFT JOIN bht_NemoDataTypes dt ON c.NemoDataType = dt.DataType 
	WHERE
		(t.parent = @GroupId OR t.parent = (SELECT TOP 1 parent FROM n_Tree WHERE id = @GroupId))
		AND (t.del IS NULL OR t.del = 0)

END

